function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
var Request = new Object();
Request = GetRequest();


var url = document.location.toString();
var arrUrl = url.split("//");
var start = arrUrl[1].indexOf("/");
var relUrl = arrUrl[1].substring(0,start);


$(function (){
     //这个就是你页面传过来的动态银行标识符,有这个变量后调用底下的方法就可以了,图片路径如果出现404,改成你这边对应正确路径就OK
    // 其他页面调用同上
    //把
    var cartType = $(".unbindCard-title").text();
    var pageStyle = getImgInfo(cartType);
    var logoImg  = pageStyle['logoImg'];
    var bgImg = pageStyle['bgImg'];
    var bgColor = pageStyle['bgColor'];
    $(this).find(".unbindCard-icon").css({'background-image':'url('+logoImg+')'});
    $(this).find(".unbindCard-item-wrapper").css({'background':bgColor});
    $(this).find(".unbindCard-bg").css({'background-image':'url('+bgImg+')'});
});

$('#bindCardList').on('click','.bindCard-item-wrapper',function(){

})

function pageAlert(txt,title){
    txt = txt ||'';
    title = title ||'提示';
    var $body =$('body');
    var $alert = $body.find('#alertPanel');
    if(!$alert.length){
        var html =  '<div class="page-alert-wrapper" id="alertPanel">'+
        '<span class="page-jumbotron" id="alertJumbotron"></span>'+
        '<div class="page-alert">'+
            '<header class="page-title" id="alertTitile">提示</header>'+
            '<div class="page-content" id="alertContent">'+
            '</div>'+
            '<footer class="page-footer"  id="alertBtn">确认</footer>'+
        '</div></div>';
        $body.append(html);
        $alert = $body.find('#alertPanel');
    }

    $('#alertTitile').text(title);   //设置标题
    $('#alertContent').text(txt);    //设置中间内容
    $('#alertPanel').show();    //弹框显示
    $('#alertPanel').off().on('click','#alertBtn,#alertJumbotron',function(){
        $('#alertPanel').hide();
    })
}



function  getImgInfo(cardType){
    var $prefix = '';
    var $before = '';
    var bgColor = '';
    var doMain = '../../../img/___payment/'; // 这个路径要改成服务器对应的地址
    switch(cardType){
        case '工商银行':
            bgColor = '#FF756A';  //找UI改成对应的背景颜色
            $prefix = 'ICBC';
            $before = '01';
            break;
        case '农业银行':
            bgColor = '#039DA4'; //找UI改成对应的背景颜色
            $prefix = 'ABC';
            $before = '02';
            break;
        case '交通银行':
            bgColor = '#3379B5'; //找UI改成对应的背景颜色
            $prefix = 'BCM';
            $before = '03';
            break;
        case '建设银行':
            bgColor = '#3379B5'; //找UI改成对应的背景颜色
            $prefix = 'CCB';
            $before = '04';
            break;
        case '中国银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'BOC';
            $before = '05';
            break;
        case '招商银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'CMB';
            $before = '06';
            break;
        case '光大银行':
            bgColor = '#FAAC4A'; //找UI改成对应的背景颜色
            $prefix = 'CEB';
            $before = '07';
            break;
        case '上海银行':
            bgColor = '#3379B5'; //找UI改成对应的背景颜色
            $prefix = 'Shanghai';
            $before = '08';
            break;
        case '北京银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'BOB';
            $before = '09';
            break;
        case '农村信用社':
        case '合作社':
            bgColor = '#039DA4'; //找UI改成对应的背景颜色
            $prefix = 'RCC';
            $before = '10';
            break;
        case '浦发银行':
            bgColor = '#3379B5'; //找UI改成对应的背景颜色
            $prefix = 'SPDBank';
            $before = '11';
            break;
        case '兴业银行':
            bgColor = '#3379B5'; //找UI改成对应的背景颜色
            $prefix = 'SG';
            $before = '12';
            break;
        case '华夏银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'HXB';
            $before = '13';
            break;
        case '中信银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'CITIC';
            $before = '14';
            break;
        case '浙商银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'CZB';
            $before = '15';
            break;
        case '广发银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'GDB';
            $before = '16';
            break;
        case '民生银行':
            bgColor = '#039DA4'; //找UI改成对应的背景颜色
            $prefix = 'CMBC';
            $before = '17';
            break;
        case '中国人民银行':
            bgColor = '#FF756A'; //找UI改成对应的背景颜色
            $prefix = 'PBC';
            $before = '18';
            break;
        default:
            bgColor = '#667188'; //找UI改成对应的背景颜色
            $prefix = 'default';
            $before = '19';
            break;
    }
    return {
        logoImg : doMain + $prefix +'_logo_'+$before+'@2x.png',
        bgImg : doMain + $prefix +'_logo_'+$before+'@2x.png',
        bgColor : bgColor
    }
}



//返回上一页
function returnBack(){
    //调用原生的返回上一页方法
    if(checkOS()=="Android")
    {
        maojia.mjGoBack();
    } else{
    setupWebViewJavascriptBridge(function(bridge) {
        bridge.callHandler('mjGoBack', function(response) {
        })
    })
    }

}

//判断是android还是IOS系统
function checkOS() {
    var ua = navigator.userAgent.toLowerCase();
    if (/iphone|ipad|ipod/.test(ua)) {
        return "IOS";
    } else if (/android/.test(ua)) {
        return "Android";
    }
}
//o家APP初始ios 注册
function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
//ios调用
setupWebViewJavascriptBridge(function(bridge) {
    bridge.registerHandler('testJSFunction', function(data, responseCallback) {
        responseCallback('js执行过了');
    })
})

/******************************** 申请支付**************************************/


function bindBankCard(cupguid){
    $.ajax({
        url:'/payment/payBindBankCard',
        type:'POST', //GET
        async:true,    //或false,是否异步
        contentType: 'application/json;charset=UTF-8',
        data:JSON.stringify({
            guid:cupguid
        }),
        dataType:'json',
        success:function(data){
            var Code = data.errorCode;
            if('0000' == Code ){
                window.open(arrUrl[0] + "//" + relUrl + "/payment/bindBankCardSuccess","_self");
            }else {
                window.open(arrUrl[0] + "//" + relUrl + "/payment/bindBankCardFail","_self");
            }
        },
        error:function(xhr,textStatus,errorThrown){
            window.open(arrUrl[0] + "//" + relUrl + "/payment/bindBankCardFail","_self");
        }
    })
}

// 获取银行名称
$('.unbindCard-footer').on('click', function (e) {
    /**/
    var cupguid = $(this).attr('id');
    bindBankCard(cupguid);
});